<script setup lang='ts'>
import TimedPublish from './buttons-timedPublish.vue'

const emits = defineEmits(['currentPublish', 'timedPublish'])
const topForm = defineModel<any>('topForm', { required: true })
const isDefault = defineModel<number>('isdefault', { required: true })
const recordsNum = defineModel<number>('recordsnum', { required: true })
const defaultGroupId = defineModel<number | null | string>('defaultGroupId', { required: true })
const timedVisible = ref(false)

const disabled = computed(() => {
    return isDefault.value === 1 && recordsNum.value > 0 && !!defaultGroupId.value && !topForm.value.isCarouselSpeedChange
})

// 立即发布
function currentPublish() {
    emits('currentPublish')
}

// 定时发布
function showTimedPublish() {
    timedVisible.value = true
}
function timedPublish(params) {
    emits('timedPublish', params)
}
</script>

<template>
    <ElCard class="mb-20 flex justify-end"
            shadow="never"
    >
        <ElButton type="primary"
                  plain
                  :disabled="disabled"
                  @click="currentPublish"
        >
            立即发布
        </ElButton>

        <ElButton type="primary"
                  plain
                  :disabled="disabled"
                  @click="showTimedPublish"
        >
            定时发布
        </ElButton>
    </ElCard>

    <!-- 定时发布弹框 -->
    <TimedPublish v-model:visible="timedVisible"
                  @confirm="timedPublish"
    />
</template>
